<?php 
include 'method/win.php';

if(isset($_GET['id'])){
    $defsql = "SELECT * FROM weibo_user where user_id='".$_GET['id']."'";
    $defres = $conn->query($defsql);
    $row = $defres->fetch_assoc();
    $sql = "SELECT weibo_list.*, weibo_user.* FROM weibo_list, weibo_user WHERE weibo_list.author = weibo_user.user_name and weibo_user.user_id = '".$_GET['id']."' order by weibo_list.public_time desc";
    $res = $conn->query($sql);
    $gzsql="select * from weibo_relation where fans='".$row['user_name']."'";
    $gzres=$conn->query($gzsql);
    $fansql="select * from weibo_relation where user='".$row['user_name']."'";
    $fanres=$conn->query($fansql);
}else {
    $defsql = "SELECT * FROM weibo_user LIMIT 1";
    $defres = $conn->query($defsql);
    $row = $defres->fetch_assoc();
    $sql = "SELECT weibo_list.*, weibo_user.* FROM weibo_list, weibo_user WHERE weibo_list.author = weibo_user.user_name and weibo_user.user_id = '".$row['user_id']."' order by weibo_list.public_time desc";
    $res = $conn->query($sql);
    $gzsql="select * from weibo_relation where fans='".$row['user_name']."'";
    $gzres=$conn->query($gzsql);
    $fansql="select * from weibo_relation where user='".$row['user_name']."'";
    $fanres=$conn->query($fansql);
}
if(isset($_SESSION['user'])){
    header("location:person_loginafter.php?id=".$_GET['id']);
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>未登录个人信息</title>
    <link rel="stylesheet" href="../lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="css/base.css">
    <link rel="stylesheet" href="css/person.css">
    <script src="../lib/jquery/jquery.js" type="text/javascript"></script>
    <script src="../lib/bootstrap/js/bootstrap.js" type="text/javascript"></script>
</head>
<body>
<!--顶部导航条-->
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <!--头部logo-->
        <div class="navbar-header">
            <a class="navbar-brand" href="#"><em><img src="../img/logo.jpg" height=30 width=30></em><em>小狗微博</em></a>
        </div>

        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <!--搜索-->
            <form class="navbar-form navbar-left" role="search" method="post" action="search.php">
                <div class="form-group">
                    <input type="text" class="form-control" style="width: 400px" placeholder="Search" name="str-search">
                </div>
                <button type="sumbit" class="btn btn-default" name="search-btn">搜索</button>
            </form>
            <!--首页、注册登录-->
            <ul class="nav navbar-nav navbar-right">
                <li><a href="index.php">首页</a></li>
                <li><a href="register.php">注册</a></li>
                <li><a href="login.php">登录</a></li>

            </ul>
        </div>
    </div>
</nav>

<!--个人版心-->
<div class="person-warp">
    <!--个人展示框-->
    <div class="person-box">
        <!--个人头像-->
        <div class="person-tx">
            <img src="../<?php echo $row['user_tx']?>" style="width: 100px; height: 100px; border-radius: 50%">
        </div>
        <!--用户名-->
        <div class="person-uname">
            <a href="person.php?id=<?php echo $row['user_id']?>"><?php echo $row['user_name']?></a>
        </div>
        <!--关注按钮-->
        <div class="gz-op choose-2">
            <button class="gz-btn" onclick="tipLogin()"><em class="glyphicon glyphicon-plus"></em><em>关注</em></button>
        </div>
    </div>

    <!--个人内容-->
    <div class="person-content clearfix">
        <!--内容左边-->
        <div class="left-content">
            <div class="person-relation clearfix">
                <a href="javascript:" onclick=tipLogin()>
                    <strong><?php echo $gzres->num_rows?></strong>
                    <span>关注</span>
                </a>
                <a href="javascript:" onclick=tipLogin()>
                    <strong><?php echo $fanres->num_rows?></strong>
                    <span>粉丝</span>
                </a>
                <a href="person.php?id=<?php echo $row['user_id']?>">
                    <strong><?php echo $res->num_rows?></strong>
                    <span>微博</span>
                </a>
            </div>

            <!--填充-->
            <div class="logo">
                <img src="../img/logo1.jpg" style="width: 260px; height: 260px">
            </div>
        </div>
        <!--内容右边-->
        <div class="right-content">
        <?php 
        if($res->num_rows){
            while ($rows = $res->fetch_assoc()){
                //         微博
                echo "<div class='weibo-box clearfix'>";
                //     	头像
                echo "<div class='author-tx'>";
                echo "<img src='../".$rows['user_tx']."' style='width: 50px; height:50px; border-radius: 50px'></div>";
                //     	微博版心
                echo "<div class='weibo-warp'><div class='author-name'><a href='person.php?id=".$rows['user_id']."'>".$rows['author']."</a></div>";
                echo "<div class='weibo-time'>".$rows['public_time']."</div>";
                echo "<div class='weibo-content'>".$rows['weibo_content']."</div>";
                //     	不是转发的微博
                if($rows['relwb_id']==""){
                    // 微博图片
                    echo "<div class='weibo-photo'>";
                    if($rows['weibo_img']){
                        echo "<img src='../".$rows['weibo_img']."' style='height: 167px; width: auto'>";
                    }
                    echo "</div>";
                }else {
                    $relsql="select weibo_list.*, weibo_user.* from weibo_list, weibo_user where weibo_user.user_name=weibo_list.author and weibo_list.weibo_id='".$rows['relwb_id']."'";
                    $relres=$conn->query($relsql);
                    if($relres->num_rows){
                        $relrow=$relres->fetch_assoc();
                        //     	转发的微博
                        echo "<div class='rel-weibo'>";
                        //     	源微博用户名
                        echo "<div class=author-name><a href='person.php?id=".$relrow['user_id']."'>@".$relrow['author']."</a></div>";
                        echo "<a href='detail.php?id=".$relrow['weibo_id']."'>";
                        //     	源微博文本
                        echo "<div class=weibo-content>".$relrow['weibo_content']."</div>";
                        //     	源微博图片
                        if($relrow['weibo_img']){
                            echo "<div class='weibo-photo'><img src='../".$relrow['weibo_img']."' style='height: 167px; width: auto'></div>";
                        }
                        //     	源微博时间及操作
                        echo "<div class='relweibo-pobox clearfix'>";
                        // 源微博时间
                        echo "<span class='relweibo-time'>".$relrow['public_time']."</span>";
                        
                        $rrsql = "select * from weibo_list where relwb_id = ".$relrow['weibo_id'];
                        $rrres = $conn->query($rrsql);
                        
                        $rcsql = "select * from weibo_comment where weibo_id = ".$relrow['weibo_id'];
                        $rcres = $conn->query($rcsql);
                        $rkcsql = "select * from weibo_kidcomment where weibo_id = ".$relrow['weibo_id'];
                        $rkcres = $conn->query($rkcsql);
                        $rcnum = ($rcres->num_rows)+($rkcres->num_rows);
                        //     	源微博操作
                        echo "<div class='relweibo-op'>";
                        echo "<span><em class='glyphicon glyphicon-comment'></em><em>".$rcnum."</em></span>";
                        echo "<span><em class='glyphicon glyphicon-share-alt'></em><em>".$rrres->num_rows."</em></span>";
                        echo "<span><em class='glyphicon glyphicon-thumbs-up'></em><em>".$relrow['weibo_zan']."</em></span>";
                        echo "</div></div></a></div>";
                    }else{
                        echo "<div class='rel-weibo'>该内容涉嫌违规，已被删除</div>";
                    }
                }
                echo "</div>";
                
                $csql = "select * from weibo_comment where weibo_id = ".$rows['weibo_id'];
                $cres = $conn->query($csql);
                $kcsql = "select * from weibo_kidcomment where weibo_id = ".$rows['weibo_id'];
                $kcres = $conn->query($kcsql);
                $cnum = ($cres->num_rows)+($kcres->num_rows);
                
                $rsql = "select * from weibo_list where relwb_id = ".$rows['weibo_id'];
                $rres = $conn->query($rsql);
                //     	微博操作
                echo "<div class='weibo-op'><a href='detail.php?id=".$rows['weibo_id']."&page=1'><span>";
                echo "<em class='glyphicon glyphicon-comment'></em><em>".$cnum."</em></span></a>";
                echo "<a href='detail.php?id=".$rows['weibo_id']."&page=2'><span>";
                echo "<em class='glyphicon glyphicon-share-alt'></em><em>".$rres->num_rows."</em></span></a>";
                echo "<a href='detail.php?id=".$rows['weibo_id']."'><span>";
                echo "<em class='glyphicon glyphicon-thumbs-up'></em><em>".$rows['weibo_zan']."</em></span></a>";
                echo "</div></div>";
            }
        }else {
            echo "该用户没有任何动态哦~";
        }

    	?>
         
        </div>
    </div>
</div>
</body>
<script>
    function tipLogin(){
        confirm("请先登录")
    }
</script>
</html>